package com.example.jyjava.controller;

import com.alibaba.fastjson.JSON;
import com.example.jyjava.service.OssService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@RequestMapping("/eduoss")
@CrossOrigin
public class OssController {
    @Resource
    private OssService ossService;

    @RequestMapping("/imgFile")
    public String UploadOssFile(MultipartFile file) {
        String falg = "400";
        String url = ossService.uploadFileAvatar(file);
//        System.out.println(url);
        HashMap<String, String> map = new HashMap<>();
        if (url != ""){
            falg = "200";
            map.put("flag",falg);
            map.put("collectNum", url);
        }else{
            map.put("flag",falg);
        }
        String s = JSON.toJSONString(map);
        return s;
    }

}
